//
// Created by liushuai on 12/14/19.
//
#include "quicksort.h"

void quicksort(int left, int right, std::vector<int> &sortVec) {
    int i = 0, j = right;
    if (left >= right)
        return;
    else {
        int privot = sortVec.at(left);
        while (i != j) {
            while (sortVec.at(j) > privot && i < j)
                j--;
            while (sortVec.at(i) <= privot && i < j)
                i++;
            if (i < j)
                std::swap(sortVec.at(i), sortVec.at(j));
        }
        if (sortVec.at(left) != sortVec.at(j))
            std::swap(sortVec.at(left), sortVec.at(j));
        quicksort(left, i - 1, sortVec);
        quicksort(i + 1, right, sortVec);
    }

}
